﻿using AconITF.Core.Models;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PTA.Until
{
	public class ExcelHelper
	{

		/// <summary>
		/// 读取信号列表
		/// </summary>
		public static List<VariableItem> ReadVarList(string path)
		{
			List<VariableItem> signals = new List<VariableItem>();
			var rows = MiniExcel.Query(path, useHeaderRow: false).ToList();
			for (int i = 1; i < rows.Count; i++)
			{
				try
				{
					VariableItem signal = new VariableItem();
					signals.Add(signal);
					signal.Id = int.Parse(rows[i].A == null ? "" : rows[i].A.ToString());
					signal.Name = rows[i].B == null ? "" : rows[i].B.ToString();
					signal.OriginalChannelIndex = int.Parse(rows[i].C == null ? "" : rows[i].C.ToString());
					signal.DataIndexNumber = int.Parse(rows[i].D == null ? "" : rows[i].D.ToString());
					signal.Project = rows[i].E == null ? "" : rows[i].E.ToString();
					signal.ConverRelationship = rows[i].F == null ? "" : rows[i].F.ToString();
					signal.CardName = rows[i].G == null ? "" : rows[i].G.ToString();

				}
				catch (Exception ex)
				{
					Console.WriteLine(ex.Message);
					continue;
				}
			}

			return signals;
		}

		private static double GetDoubleValue(string str)
		{
			if (double.TryParse(str, out double value))
			{
				return value;
			}

			return 0;
		}

		private static int GetSignalType(string str)
		{
			if (str == "输入")
			{
				return 0;
			}
			else if (str == "输出")
			{
				return 1;
			}
			return -1;
		}
	}
}
